﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BluePortal.Medias.Core
{
    public class BCPicture : BCMedia<Picture>
    {
        public void Create(Picture item)
        {
            if (item.ID == Guid.Empty) item.ID = Guid.NewGuid();
            item.PublishDate = DateTime.Now;
            item.Status = (int)MediaStatus.Online;
            Context.Medias.InsertOnSubmit(item);
            Context.SubmitChanges();
        }
        
        public Picture FindPicureByID(Guid id)
        {
            return Context.Pictures.SingleOrDefault(v => v.ID == id);
        }

        public void Update(Picture item)
        {
            var query = Context.Pictures.SingleOrDefault(v => v.ID == item.ID);
            if (query != null)
            {
                query.Description = item.Description;
                query.Image = item.Image;
                query.Preview = item.Preview;                
                query.Status = item.Status;
                query.Title = item.Title;
                query.Rating = item.Rating;
                query.IsPrivate = item.IsPrivate;
                query.ParentalRating = item.ParentalRating;
                Context.SubmitChanges();
            }
        }

    }
}
